package com.demo.event.controller;

import com.demo.event.dto.UserDto;
import com.demo.event.service.UserLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 *
 * @author
 * @since
 */
@RestController
@Slf4j
public class TestController {

  @Autowired
  private UserLoginService userLoginService;

  @GetMapping("/login/{name}/{age}")
  public String login(@NotNull @PathVariable String name, @NotNull @PathVariable Integer age){
    log.info("接收到 login 请求");
    try {
      userLoginService.loginSucc(UserDto.builder().userName(name).age(age).build());
      log.info("处理 login 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "login Exception";
    }
    return "login succ";
  }

  @GetMapping("/login01/{name}/{age}")
  public String login01(@NotNull @PathVariable String name, @NotNull @PathVariable Integer age){
    log.info("接收到 login01 请求");
    try {
      userLoginService.loginSucc01(UserDto.builder().userName(name).age(age).build());
      log.info("处理 login01 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "login01 Exception";
    }
    return "login01 succ";
  }

  @GetMapping("/login02/{name}/{age}")
  public String login02(@NotNull @PathVariable String name, @NotNull @PathVariable Integer age){
    log.info("接收到 login02 请求");
    try {
      userLoginService.loginSucc02(UserDto.builder().userName(name).age(age).build());
      log.info("处理 login02 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "login02 Exception";
    }
    return "login02 succ";
  }
}
